package org.crmsystem.util;

import java.security.MessageDigest;

/**
 * 按一定规则自动生成主键类
 * @author Administrator
 */
public class GeneraterKey {
	/**
	 * 输入字符串转化为32位的MD5字符串返回
	 * @param str
	 * @return
	 */
	public static String str2md5(String str) {
		String s = null;
		try {
			MessageDigest md5 = MessageDigest.getInstance("MD5");
			md5.update(str.getBytes("UTF-8"));
			byte[] m = md5.digest();
			StringBuilder sb = new StringBuilder();
			for (byte b : m) {
				int bb = Byte.toUnsignedInt(b);

				if (bb <= 0xf) {
					sb.append(0);
				}
				sb.append(Integer.toHexString(bb));
			}
			s = sb.toString();
		} catch (Exception e) {
			s = null;
		}

		return s;
	}
}
